define(function () {

    var self, footData = {
        index: 0
    };

    var gwat310 = app.Module.extend({

        init: function () {
            self = this;
            self.mData = {};
            self.searchData = {
                keyword: ''
            };
            self._super({
                _tag: 'p_gwat310', // key, 对象放进pageModule
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true //自动加载刷新控件
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1', 'scroll2'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/shhb/getList",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    type: goods.type.replace('scroll', ''),
                    keyword: self.searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data.addMap({checked:false});
                        _super.call(self,{
                            obj: goods,
                            data: data,
                            nodata: {
                                0: '无未回报订单...',
                                1: '无已回报订单...',
                            }
                        });
                    }
                }
            });
        },
        _slide: function (i) {
            footData.index = i;
        },
        _search:function(d){
            self.searchData.keyword = d.keyword.trim();
            self._refresh();
        },
        _ready:function () {

            Vue.component('shhb-listitem', {
                template: app.getByid(doc, 'item-template'),
                props: {
                    model: Array
                },
                methods: {
                    statueN: function (item) {
                        if (item.GWEC103 == undefined || item.GWEC103 == 'N') {
                            return true;
                        } else {
                            return false;
                        }
                    },
                    statueY: function (item) {
                        if (item.GWEC103 == 'Y') {
                            return true;
                        } else {
                            return false;
                        }
                    },
                    statueImg: function (item) {
                        if (item.GWEC103 == 'Y') {
                            return 'comfirom';
                        } else if (item.GWEC103 == undefined || item.GWEC103 == 'N') {
                            return 'nonComfirom';
                        } else {
                            return '';
                        }
                    },
                    hb: function (item) {
                        app.openPage({

                            src: "shhb/shbb-info.html",
                            args: {
                                item:item,
                                cb:function () {
                                    self._refresh();
                                }
                            },

                        });
                    },
                    cancle: function (item) {
                        app.confirm({
                            msg: '是否取消确认？',
                            ok: function (e) {
                                app.ajax({
                                    xurl: "api/wx/shhb/save",
                                    loading: true,
                                    xdata: {
                                        GWECDOCNO: item.GWECDOCNO,
                                        GWEC103:'N'
                                    },
                                    cb: function (result) {
                                        if (result.ok) {
                                            self._getRefreshObj().data.remove(item);
                                            app.toast('取消回报成功');
                                            self._refresh();
                                        } else {
                                            app.toast(result.data.message);
                                        }
                                    }
                                });
                            }
                        });
                    },
                    // del: function (item) {
                    //     app.confirm({
                    //         msg: '是否作废？',
                    //         ok: function (e) {
                    //             app.ajax({
                    //                 xurl: "api/wx/gwat310/delete",
                    //                 loading: true,
                    //                 xdata: {
                    //                     obj: app.jsonString(item)
                    //                 },
                    //                 cb: function (result) {
                    //                     if (result.ok) {
                    //                         self._getRefreshObj().data.remove(item);
                    //                         app.toast('作废成功');
                    //                     } else {
                    //                         app.toast(result.data.message);
                    //                     }
                    //                 }
                    //             });
                    //         }
                    //     });
                    // }
                }
            });

        },
        _lazy:function () {
            this._super();

            new Vue({
                el: doc.getElementById('footer'),
                data: footData,
                methods: {
                    checkall: function () {
                        var items = self._getRefreshObj().data;
                        for (var i = 0; i < items.length; i++) {
                            items[i].checked = true;
                        }
                    },
                    reconfirmlist: function () {
                        var items = [];
                        var list = self._getRefreshObj().data;
                        for (var i = 0; i < list.length; i++) {
                            if (list[i].checked == true) {
                                items.push(list[i])
                            }
                        }
                        app.confirm({
                            msg: '是否取消确认？',
                            ok: function (e) {
                                if (items.length == 0) {
                                    app.toast('无选中项');
                                    return;
                                }
                                app.ajax({
                                    xurl: "api/wx/gwat310/reconfirmlist",
                                    loading: true,
                                    xdata: {
                                        items: JSON.stringify(items)
                                    },
                                    cb: function (result) {
                                        if (result.ok) {
                                            app.toast('批量取消确认成功');
                                            for (var i = 0; i < result.data.data.length; i++) {
                                                for (var j = 0; j < items.length; j++) {
                                                    if (items[j].GWCSDOCNO == result.data.data[i].GWCSDOCNO) {
                                                        list.remove(items[j]);
                                                    }
                                                }
                                            }
                                        } else {
                                            app.toast(result.data.message);
                                        }
                                    }
                                });
                            }
                        });
                    },
                    confirmlist: function () {
                    },
                    deletelist: function () {
                        var items = [];
                        var list = self._getRefreshObj().data;
                        for (var i = 0; i < list.length; i++) {
                            if (list[i].checked == true) {
                                items.push(list[i])
                            }
                        }
                        if (items.length == 0) {
                            app.toast('无选中项');
                            return;
                        }
                        app.confirm({
                            msg: '是否作废？',
                            ok: function (e) {
                                app.ajax({
                                    xurl: "api/wx/gwat310/deletelist",
                                    loading: true,
                                    xdata: {
                                        items: JSON.stringify(items)
                                    },
                                    cb: function (result) {
                                        for (var i = 0; i < result.data.data.length; i++) {
                                            for (var j = 0; j < items.length; j++) {
                                                if (items[j].GWCSDOCNO == result.data.data[i].GWCSDOCNO) {
                                                    list.remove(items[j]);
                                                }
                                            }
                                        }
                                        if (result.ok) {
                                            app.toast('批量作废成功');
                                        } else {
                                            app.toast(result.data.message);
                                        }
                                    }
                                });
                            }
                        });
                    }
                }
            });
        }
    });

    return new gwat310();

});